import { storage } from './../../assets/js/util/index'

const user = {
    namespaced: true,
    state: {
        count: 0,
        token: '',
        userInfo: {}
    },
    mutations: {
        // 存储token
        setToken (state, payload = '') {
            state.token = payload
            storage.set('token', payload)
        },
        increment (state) {
            // 这里的 `state` 对象是模块的局部状态
            state.count++
        }
    },
    actions: {
        incrementIfOddOnRootSum ({ dispatch, state, commit, rootState }) {
            commit('increment')
        }
    },
    getters: {
        sumWithRootCount (state, getters, rootState, rootGetters) {
            return state.count + rootState.count
        }
    }
}
export default user
